package com.jumaojiang.controller;

import com.jumaojiang.wxpusher.bean.callback.CallBackData;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * forward
 *
 * @author wuhanwei
 * @version 1.0
 * @date 2021/11/5
 */
@Component
public class ThreadPoolData {

    // 线程池, 存储线程, map中的key为服务器生成的authCode
    private Map<String, UserData> threadMap = new HashMap<>();

    public ThreadPoolData() {
    }

    public UserData getThreadData(String key) {
        return threadMap.get(key);
    }

    public void removeMap(String key){
        threadMap.remove(key);
    }

    public boolean setThreadData(String key, UserData userData) {
        UserData res = threadMap.put(key, userData);
        // 返回null则put成功
        if(res == null){
            return true;
        }
        return false;
    }

    public static class UserData{
        // 登陆验证阻塞等待的线程
        private Thread thread;
        // wxpusher发送给服务器的数据
        private CallBackData callBackData;

        public UserData() {
        }

        public Thread getThread() {
            return thread;
        }

        public void setThread(Thread thread) {
            this.thread = thread;
        }

        public CallBackData getCallBackData() {
            return callBackData;
        }

        public void setCallBackData(CallBackData callBackData) {
            this.callBackData = callBackData;
        }
    }
}
